package tennos;

import static mathUtils.VecMath.*;
import drawing.Drawable;
import integration.Integrable;
import processing.core.PApplet;

public class Fleck implements Integrable, Drawable {
	public PApplet parent;
	
	public float s[][];
	public float ds[][];
	
	Fleck(PApplet p, int n) {
		this(p, new float[2][n]);
	}
	Fleck(PApplet p) {
		this(p, 2);
	}
	Fleck(PApplet p, float px, float py, float vx, float vy) {
		this(p, 2);
		s[0][0] = px;
		s[0][1] = py;
		s[1][0] = vx;
		s[1][1] = vy;
	}
	Fleck(PApplet p, float[][] s_) {
		parent = p;
		s = s_;
		ds = new float[2][2];
	}
	Fleck(PApplet p, float[] p_, float[] v_) {
		parent = p;
		s = new float[2][];
		s[0] = p_;
		s[1] = v_;
		ds = new float[2][2];
		vecCopy(s[1], ds[0]);
	}
	
	float[] position() {return s[0];}
	float[] velocity() {return s[1];}
	float[] acceleration() {return ds[1];}
	
	public float[][] state() {return s;}
	public float[][] dstate() {return ds;}
	
	public void findSlope() {
		vecCopy(s[1], ds[0]);
		vecZero(ds[1]);
	}
	
	public void advanceState(float dt) {
		vecAddScaled(s, ds, dt, s);
	}
	
	public void draw() {
		parent.ellipse(position()[0], position()[1], 1.0f, 1.0f);
	}
}
